package com.yzt.minemodule.wallet.dialog;

import android.view.View;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.yzt.zhuju.dialog.BottomBaseDialog;
import com.yzt.zhuju.network.entity.mine.wallet.WalletScreenEntry;
import com.yzt.minemodule.R;
import com.yzt.minemodule.wallet.adapter.WalletLabelAdapter;
import com.yzt.p_base.utils.DisplayUtils;

import java.util.List;

import io.rong.imkit.picture.decoration.GridSpacingItemDecoration;

/**
 * 功能：收支筛选弹窗
 */
public class WalletLabelDialog extends BottomBaseDialog {

    private WalletLabelAdapter mWalletScreenAdapter;

    private OnClickScreenListener listener;

    private List<WalletScreenEntry> mList;

    private WalletScreenEntry mWalletScreenEntry;

    private int mPosition;

    public void setListener(OnClickScreenListener listener) {
        this.listener = listener;
    }

    @Override
    public int getLayoutRes() {
        return R.layout.dialog_fragment_wallet_screen;
    }

    @Override
    public void bindView(View v) {
        RecyclerView mWalletScreenRv = v.findViewById(R.id.wallet_screen_rv);
        mWalletScreenAdapter = new WalletLabelAdapter();
        mWalletScreenRv.addItemDecoration(new GridSpacingItemDecoration(4, DisplayUtils.dp2px(14), true));
        mWalletScreenRv.setLayoutManager(new GridLayoutManager(mActivity, 4));
        mWalletScreenRv.setAdapter(mWalletScreenAdapter);

        mWalletScreenAdapter.addChildClickViewIds(R.id.wallet_screen_tv);
        mWalletScreenAdapter.setOnItemChildClickListener((adapter, view, position) -> {
            if (view.getId() == R.id.wallet_screen_tv) {
                for (WalletScreenEntry walletScreenEntry : mList) {
                    walletScreenEntry.setCheck(false);
                }
                mWalletScreenEntry = mList.get(position);
                mPosition = position;
                mList.get(position).setCheck(true);
                mWalletScreenAdapter.setList(mList);
            }
        });

        mWalletScreenAdapter.setList(mList);
        v.findViewById(R.id.ubi_recharge_tv).setOnClickListener(v1 -> {
            if (listener != null) {
                listener.selectScreen(mPosition, mWalletScreenEntry);
            }
            dismiss();
        });
    }

    public void setList(List<WalletScreenEntry> mList) {
        this.mList = mList;
    }

    public interface OnClickScreenListener {

        void selectScreen(int position, WalletScreenEntry entry);
    }
}
